﻿package com.tudou.home.controller.ad
{
    import com.tudou.ad.consts.*;
    import com.tudou.ad.data.*;
    import com.tudou.ad.interfaces.*;
    import com.tudou.home.commands.*;
    import com.tudou.home.commands.ad.*;
    import com.tudou.home.consts.*;
    import com.tudou.home.model.*;
    import com.tudou.home.model.ad.*;
    import com.tudou.home.view.*;
    import com.tudou.track.*;
    import flash.geom.*;
    import org.puremvc.as3.interfaces.*;
    import org.puremvc.as3.patterns.command.*;

    public class AdPlacardCommand extends SimpleCommand
    {

        public function AdPlacardCommand()
        {
            return;
        }// end function

        private function sendAop(param1:String, param2:IAdItemInfo) : void
        {
            var _loc_3:* = facade.retrieveProxy(AdProxy.NAME) as AdProxy;
            if (_loc_3.adTracker && param2)
            {
                _loc_3.adTracker.adSend(param2, AdData.getInst().adThrowInfo, param1, null);
            }
            return;
        }// end function

        private function adClear() : void
        {
            var _loc_1:* = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
            var _loc_2:* = facade.retrieveProxy(AdPlacardProxy.NAME) as AdPlacardProxy;
            var _loc_3:* = facade.retrieveMediator(ViewMediator.NAME) as ViewMediator;
            if (_loc_2.adItemInfo)
            {
                _loc_1.stopDelayTimer();
                _loc_3.removeAdPlacard();
                _loc_2.clearAd();
            }
            return;
        }// end function

        override public function execute(param1:INotification) : void
        {
            var _loc_7:Rectangle = null;
            var _loc_2:* = facade.retrieveProxy(AdInfoProxy.NAME) as AdInfoProxy;
            var _loc_3:* = facade.retrieveProxy(PlayerProxy.NAME) as PlayerProxy;
            var _loc_4:* = facade.retrieveProxy(AdPlacardProxy.NAME) as AdPlacardProxy;
            var _loc_5:* = facade.retrieveMediator(ViewMediator.NAME) as ViewMediator;
            var _loc_6:* = _loc_2.getCurrAdItemByType(AdType.PLACARD) as IAdItemInfo;
            var _loc_8:* = param1.getBody();
            var _loc_9:int = 0;
            switch(param1.getName())
            {
                case AdPlacardCommandSet.START:
                {
                    _loc_4.adItemInfo = _loc_6;
                    _loc_4.adThrowInfo = _loc_2.throwInfo;
                    _loc_4.startAd();
                    break;
                }
                case AdPlacardCommandSet.CLEAR:
                {
                    _loc_9 = AdModStatus.CLEAR;
                    break;
                }
                case AdPlacardCommandSet.TIMEOUT_START_PLAY:
                {
                    if (_loc_4 && _loc_4.adItemInfo)
                    {
                        _loc_4.timeoutStartPlay();
                        _loc_9 = AdModStatus.COMPLETE;
                    }
                    break;
                }
                case AdPlacardCommandSet.PREPARE_TO_SHOW:
                {
                    _loc_3.stopDelayTimer();
                    if (!_loc_3.playerStatus.hasStartPlay)
                    {
                        _loc_9 = AdModStatus.START_LOAD;
                        _loc_4.startView();
                        if (_loc_4 && _loc_4.view)
                        {
                            _loc_5.setAdPlacard(_loc_4.view.adDisplay);
                        }
                    }
                    break;
                }
                case ViewCommandSet.ENTER_FULLSCREEN_AND_RESIZE:
                {
                    if (!_loc_3.playerStatus.hasStartPlay && _loc_4 && _loc_4.adItemInfo)
                    {
                        sendAop(NodeLog.AD_FULLSCREEN_SKIP, _loc_4.adItemInfo);
                        _loc_9 = AdModStatus.COMPLETE;
                    }
                    break;
                }
                case ViewCommandSet.NORMALSCREEN_RESIZE:
                {
                    if (_loc_4 && _loc_4.view)
                    {
                        _loc_7 = PlayerConsts.NORMALSCREEN_RECT;
                        _loc_4.view.goTransform(_loc_7.width, _loc_7.height, false);
                    }
                    break;
                }
                case ViewCommandSet.EXPAND_STAGE:
                {
                    if (_loc_4 && _loc_4.view)
                    {
                        _loc_4.view.isExpand = _loc_8;
                    }
                    break;
                }
                case AdPlacardCommandSet.ERROR_END:
                {
                    _loc_9 = AdModStatus.COMPLETE;
                    break;
                }
                case AdPlacardCommandSet.SHOW_START:
                {
                    _loc_2.isFormerAdShowed = true;
                    _loc_2.addFormerAdShowed(_loc_6.aid);
                    break;
                }
                case AdPlacardCommandSet.SHOW_END:
                {
                    _loc_9 = AdModStatus.COMPLETE;
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            switch(_loc_9)
            {
                case AdModStatus.START_PLAY:
                {
                    adClear();
                    sendNotification(AdFrontMultiCommandSet.START_PLAY);
                    break;
                }
                case AdModStatus.START_LOAD:
                {
                    sendNotification(AdFrontMultiCommandSet.START_LOAD);
                    break;
                }
                case AdModStatus.CLEAR:
                {
                    adClear();
                    break;
                }
                case AdModStatus.COMPLETE:
                {
                    adClear();
                    sendNotification(AdFrontMultiCommandSet.COMPLETE);
                    break;
                }
                default:
                {
                    break;
                    break;
                }
            }
            return;
        }// end function

    }
}
